#pragma once
#include <windows.h>
#include "Log/LOG.h"
/*************************************
typedef DWORD threadid;
class CThread
{
public:
	CThread(void);
	~CThread(void);
	static DWORD WINAPI ThreadFunc(LPVOID pv)
	{
		try
		{
			(reinterpret_cast<thread *>(pv))->run();
		}
		catch()
		{
		}
	}
	static threadid getthreadid()
	{
		return ::GetCurrentThreadId();
	}
	static void sleep(long milliseconds=1)
	{
		Sleep(milliseconds);
	}
	threadid start()
	{
		threadid id;
		::CreateThread(NULL,0,ThreadFunc,this,0,&kid);
		return id;
	}
	virtual void run()=0;
};
**********************************************/



// define the interface
struct IRunnable {
  virtual void run() = 0;
};

// define the thread class
class CThread {
public:
	CThread(void);
	~CThread(void);
  CThread(IRunnable *ptr) {
    _threadObj = ptr;
  }
  void start() {
    // use the Win32 API here
    DWORD threadID;
    ::CreateThread(0, 0, threadProc, _threadObj, 0, &threadID);
  }
  
protected:
  // Win32 compatible thread parameter and procedure 
  IRunnable *_threadObj; 
  static unsigned long __stdcall threadProc(void* ptr) {
    ((IRunnable*)ptr)->run();
    return 0;
  }   
};
